﻿using RFID_Interface.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace RFID_Interface
{
    /// <summary>
    /// RFID 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://wy.person/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class K3Service : System.Web.Services.WebService
    {

        /// <summary>
        /// 获取条码信息
        /// </summary>
        [WebMethod(Description = "IF01.获取条码信息")]
        public BarcodeInfo[] Get_Barcode_Info(string[] barcode)
        {
            if (barcode == null || barcode.Length == 0) return new BarcodeInfo[0];
            return barcode.Select(BarcodeInfo.Get).ToArray();
        }

        /// <summary>
        /// 获取商品信息
        /// </summary>
        [WebMethod(Description = "IF02.获取商品信息")]
        public ICItemInfo[] Get_Material_Master(string[] number)
        {
            if (number == null || number.Length == 0)
                return ICItemInfo.GetAll().ToArray();
            else
                return number.Select(ICItemInfo.Get).ToArray();
        }

        [WebMethod(Description = "IF03.增加入库单据")]
        public RecieveBillResponse Send_Goods_Recieve(RecieveBill bill)
        {
            try
            {
                if (bill == null) return new RecieveBillResponse { Result = 'F', ErrMsg = "传入的单据对象不能为空" };
                return bill.Save();
            }
            catch (Exception ex)
            {
                return new RecieveBillResponse { Result = 'F', ErrMsg = ex.Message };
            }
        }

        [WebMethod(Description = "IF04.增加调拨单据")]
        public TransferBillResponse Send_Transfer(TransferBill bill)
        {
            try
            {
                if (bill == null) return new TransferBillResponse { Result = 'F', ErrMsg = "传入的单据对象不能为空" };
                return bill.Save();
            }
            catch (Exception ex)
            {
                return new TransferBillResponse { Result = 'F', ErrMsg = ex.Message };
            }
        }

        [WebMethod(Description = "IF05.获取库存信息")]
        public List<InventoryInfo> Get_StockInfo(string stockNumber, string icitemNumber, string iventoryScheme)
        {
            if (string.IsNullOrEmpty(iventoryScheme))
            {
                return InventoryInfo.Query(stockNumber, icitemNumber);
            }
            else
            {
                return InventoryInfo.QueryPDSchema(stockNumber, icitemNumber, iventoryScheme);
            }
        }

        [WebMethod(Description = "IF06.接收仓库盘点实存数据")]
        public StockTakeResponse Send_StockTake(StockTakeRequest request)
        {
            try
            {
                if (request == null) return new StockTakeResponse { Result = 'F', ErrMsg = "传入的数据对象不能为空" };
                return request.Save();
            }
            catch (Exception ex)
            {
                return new StockTakeResponse { Result = 'F', ErrMsg = ex.Message };
            }
        }

        [WebMethod(Description = "IF07.获取发货单信息")]
        public DeliveryBillResponse Get_Delivery_Document(string stockNumber, string billNo)
        {
            return DeliveryBillResponse.Get(billNo);
        }

        [WebMethod(Description = "IF08.发送发货单信息")]
        public SendDeliveryResponse Send_Delivery_Document(SendDeliveryRequest request)
        {
            try
            {
                if (request == null) return new SendDeliveryResponse { Result = 'F', ErrMsg = "传入的单据对象不能为空" };
                return request.Save();
            }
            catch (Exception ex)
            {
                return new SendDeliveryResponse { Result = 'F', ErrMsg = ex.Message };
            }
        }

        [WebMethod(Description = "IF09.获取发货单冲红信息")]
        public DeliveryBillResponse Get_Reverse_Document(string stockNumber, string billNo)
        {
            return DeliveryBillResponse.Get(billNo);
        }

        [WebMethod(Description = "IF10.发送发货冲红单信息")]
        public SendDeliveryResponse Send_Reverse_Document(SendDeliveryRequest request)
        {
            try
            {
                if (request == null) return new SendDeliveryResponse { Result = 'F', ErrMsg = "传入的单据对象不能为空" };
                return request.Save();
            }
            catch (Exception ex)
            {
                return new SendDeliveryResponse { Result = 'F', ErrMsg = ex.Message };
            }
        }

        [WebMethod(Description = "IF11.获取仓库列表")]
        public List<Stock> Get_Warehouse_Structure()
        {
            return Stock.GetAll();
        }

        [WebMethod(Description = "IF12.获取用户列表")]
        public List<User> Get_User_List()
        {
            return DTO.User.GetAll();
        }

        [WebMethod(Description = "IF13.获取部门列表")]
        public List<Dep> Get_Department()
        {
            return Dep.GetAll();
        }

        [WebMethod(Description = "IF14.获取职员列表")]
        public List<Employee> Get_Employee()
        {
            return Employee.GetAll();
        }


        [WebMethod(Description = "IF15.获取发货单列表")]
        public DeliveryListResponse Get_Delivery_List(string stocknumber, DateTime datebegin, DateTime dateend)
        {
            return DeliveryListResponse.Get(stocknumber, datebegin, dateend, DeliveryBillInfo.pROB == 1);
        }

        [WebMethod(Description = "IF16.获取发货冲红单列表")]
        public DeliveryListResponse Get_Reverse_List(string stocknumber, DateTime datebegin, DateTime dateend)
        {
            return DeliveryListResponse.Get(stocknumber, datebegin, dateend, DeliveryBillInfo.pROB == -1);
        }
    }
}
